<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\api;

use App\Common\CommonAbstract;

use App\Service\User\PlatformOrderService;
use App\Service\User\UserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;

/**
 * 渠道商回调控制器
 *
 * @AutoController()
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\api
 */
class ChannelNotifyController extends CommonAbstract
{
    /**
     * @Inject
     * @var PlatformOrderService
     */
    private $platform_order;

    // 渠道商回调
    public function channel()
    {

        $params = $this->request->all();

        // 记录日志
        $this->logger('payment')->info(json_encode($params), [
            'channel'
        ]);

        if( $params['type'] !== "charge.succeeded" ) {
            $this->logger('payment')->info("回调失败,支付失败");
            return $this->response->raw('success');
        }

        if( substr( $params['data']['object']['order_no'] , 0,7) != "channel" ) {
            $this->logger('payment')->info("回调失败，场景错误".substr( $params['data']['object']['order_no'] , 0,7));
            return $this->response->raw('success');
        }

        $this->platform_order->pingNotify($params['data']['object']);

        return $this->response->raw('success');
    }
}